package com.sgb.kjwl.view.ui.adapter.material;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.sgb.kjwl.view.widget.DictWindow6;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.MLog;

import java.util.ArrayList;
import java.util.List;

public class MaterialFilterAdapter3 extends BaseRecycleAdapter<DictEntity3> {

    private int index;
    private DictWindow6 dictWindow6;
    private boolean check = false;
    private int type;
    private TextView tv_name;

    public MaterialFilterAdapter3(Context context, List<DictEntity3> datas) {
        super(context, R.layout.item_filter_material3, datas);
        dictWindow6 = new DictWindow6(context);
    }

    @Override
    public void convert(ItemViewHolder holder, final DictEntity3 entity) {
        holder.setBinding(BR.viewModel, entity);
        tv_name = holder.getItem().findViewById(R.id.tv_name);
        if (type == 1) {
            if ("全部".equals(entity.getName())){
                tv_name.setText(entity.getName());
            }else {
                tv_name.setText(entity.getName() + "Km以内");
            }
        } else {
            tv_name.setText(entity.getName());
        }
    }

    public void showChildWindow(ItemViewHolder holder, List<DictEntity3> dictEntity3List, int position) {
        holder.setIsRecyclable(false);
        RelativeLayout rootLayout = holder.getItem().findViewById(R.id.root_layout);

        dictWindow6.setData(dictEntity3List);
        dictWindow6.showPopwindow2(rootLayout);
        dictWindow6.setOnCallBack(new DictWindow6.OnCallBack() {
            @Override
            public void result(DictEntity3 dictEntity) {
                check = true;
                getDatas().get(position).setName(dictEntity.getName());
                getDatas().get(position).setId(dictEntity.getId());
                getDatas().get(position).setChildCheck(true);
                notifyDataSetChanged();
            }
        });
        dictWindow6.setOnCloseBack(new DictWindow6.OnCloseBack() {
            @Override
            public void dismiss() {
                if (!check) {
                    getCheckDatas().remove(getDatas().get(position));
                    getCheckList().put(position, false);
                    notifyDataSetChanged();
                }
                check = false;
            }
        });
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public void setStringName(int type) {
        this.type = type;
    }
}
